// Decompiled on 周六 2月 22 19:31:49 CST 2025 with Zomboid Decompiler v0.1.3 using Vineflower.
package zombie.commands.serverCommands;

import zombie.characters.IsoPlayer;
import zombie.characters.IsoZombie;
import zombie.commands.CommandArgs;
import zombie.commands.CommandBase;
import zombie.commands.CommandHelp;
import zombie.commands.CommandName;
import zombie.commands.RequiredRight;
import zombie.core.Rand;
import zombie.core.logger.LoggerManager;
import zombie.core.raknet.UdpConnection;
import zombie.iso.IsoDirections;
import zombie.iso.IsoGridSquare;
import zombie.iso.IsoWorld;
import zombie.network.GameServer;

@CommandName(
    name = "createhorde"
)
@CommandArgs(
    required = {"(\\d+)"},
    optional = "(.+)"
)
@CommandHelp(
    helpText = "UI_ServerOptionDesc_CreateHorde"
)
@RequiredRight(
    requiredRights = 56
)
public class CreateHordeCommand extends CommandBase {
    public CreateHordeCommand(String username, String userAccessLevel, String command, UdpConnection connection) {
        super(username, userAccessLevel, command, connection);
    }

    @Override
    protected String Command() {
        Integer integer = Integer.parseInt(this.getCommandArg(Integer.valueOf(0)));
        String string = this.getCommandArg(Integer.valueOf(1));
        IsoPlayer isoPlayer = null;
        if (this.getCommandArgsCount() == 2) {
            isoPlayer = GameServer.getPlayerByUserNameForCommand(string);
            if (isoPlayer == null) {
                return "User \"" + string + "\" not found";
            }
        } else if (this.connection != null) {
            isoPlayer = GameServer.getAnyPlayerFromConnection(this.connection);
        }

        if (integer == null) {
            return this.getHelp();
        } else {
            integer = Math.min(integer, 500);
            if (isoPlayer != null) {
                for (int _int = 0; _int < integer; _int++) {
                    zombie.VirtualZombieManager.instance.choices.clear();
                    IsoGridSquare isoGridSquare = IsoWorld.instance
                        .CurrentCell
                        .getGridSquare(
                            (double)Rand.Next(isoPlayer.getX() - 10.0F, isoPlayer.getX() + 10.0F),
                            (double)Rand.Next(isoPlayer.getY() - 10.0F, isoPlayer.getY() + 10.0F),
                            (double)isoPlayer.getZ()
                        );
                    zombie.VirtualZombieManager.instance.choices.add(isoGridSquare);
                    IsoZombie isoZombie = zombie.VirtualZombieManager.instance
                        .createRealZombieAlways(IsoDirections.fromIndex(Rand.Next(IsoDirections.Max.index())).index(), false);
                    if (isoZombie != null) {
                        zombie.ZombieSpawnRecorder.instance.record(isoZombie, this.getClass().getSimpleName());
                    }
                }

                LoggerManager.getLogger("admin")
                    .write(
                        this.getExecutorUsername() + " created a horde of " + integer + " zombies near " + isoPlayer.getX() + "," + isoPlayer.getY(),
                        "IMPORTANT"
                    );
                return "Horde spawned.";
            } else {
                return "Specify a player to create the horde near to.";
            }
        }
    }
}
